import React from 'react';
import {Tooltip, Popconfirm, Button, message} from 'antd';
import {DeleteOutlined} from '@ant-design/icons';
import {ButtonType} from "antd/es/button";
import {Access} from "umi"; // 假设 Access 组件在 @/components/Access

export interface AccessDeleteBtnProps {
  accessKey: boolean; // 权限检查的键值
  tooltipTitle?: string; // 工具提示的标题
  popconfirmTitle?: string; // 确认对话框的标题
  onDelete: () => Promise<any>; // 删除操作的函数
  buttonType?: ButtonType; // 按钮类型
  danger?: boolean; // 是否显示为危险按钮
  icon?: React.ReactNode; // 自定义按钮图标
  disabled?: boolean;
  children?: React.ReactElement; // 自定义 children
}

const AccessDeleteBtn: React.FC<AccessDeleteBtnProps> = ({
                                                           accessKey,
                                                           tooltipTitle = '删除该条记录',
                                                           popconfirmTitle = '删除该条记录吗？',
                                                           onDelete,
                                                           disabled = false,
                                                           buttonType,
                                                           danger = true,
                                                           icon = <DeleteOutlined/>,
                                                           children,
                                                         }) => {
  return (
    <Access accessible={accessKey}>
      <Tooltip title={tooltipTitle}>
        <Popconfirm title={popconfirmTitle} onConfirm={onDelete}>
          {children ? children : (
            <Button
              disabled={disabled}
              danger={danger}
              type={buttonType}
              icon={icon}
            />
          )}
        </Popconfirm>
      </Tooltip>
    </Access>
  );
};

export default AccessDeleteBtn;
